# x = {8: {'children': [{'id': 3, 'authName': '角色列表', 'url': '/roles/', 'level': '1', 'pid': 8}, {'id': 6, 'authName': '权限列表', 'url': '/rights/', 'level': '1', 'pid': 8}]}, 7: {'children': [{'id': 4, 'authName': '用户列表', 'url': '/users/', 'level': '1', 'pid': 7}]}, 4: {'children': [{'id': 5, 'authName': '添加客户', 'url': '/users/add/', 'level': '2', 'pid': 4}, {'id': 9, 'authName': '修改客户', 'url': '/users/edit/', 'level': '2', 'pid': 4}]}, 3: {'children': [{'id': 10, 'authName': '添加角色', 'url': '/roles/add/', 'level': '2', 'pid': 3}, {'id': 11, 'authName': '修改角色', 'url': '/roles/edit/', 'level': '2', 'pid': 3}]}}
x = {(1, 8): {'children': [{'id': 3, 'authName': '角色列表', 'url': '/roles/', 'level': '1', 'pid': 8}, {'id': 6, 'authName': '权限列表', 'url': '/rights/', 'level': '1', 'pid': 8}]}, (1, 7): {'children': [{'id': 4, 'authName': '用户列表', 'url': '/users/', 'level': '1', 'pid': 7}]}, (1, 4): {'children': [{'id': 5, 'authName': '添加客户', 'url': '/users/add/', 'level': '2', 'pid': 4}, {'id': 9, 'authName': '修改客户', 'url': '/users/edit/', 'level': '2', 'pid': 4}]}, (1, 3): {'children': [{'id': 10, 'authName': '添加角色', 'url': '/roles/add/', 'level': '2', 'pid': 3}, {'id': 11, 'authName': '修改角色', 'url': '/roles/edit/', 'level': '2', 'pid': 3}]}, (2, 7): {'children': [{'id': 4, 'authName': '用户列表', 'url': '/users/', 'level': '1', 'pid': 7}]}}
role_dict = {1: {'id': 1, 'roleName': '运维', 'roleDesc': 'yunwei'}, 2: {'id': 2, 'roleName': '研发', 'roleDesc': 'yanfa'}}
menu_list  = [1,2,3]
third_dict = {}
third_id_list = []
for k,v in x.items():
    # print(k,v)
	# third_dict[k] = v
	# print(k,v['children'][0]['id'])
	#{'id': 5, 'authName': '添加客户', 'url': '/users/add/', 'level': '2', 'pid': 4}
	t = v['children'][0]
	# print('xxx', t['id'])
	for i in menu_list:
		if (i,t['id']) in x:

			# print('11111111111111111',(i,t['id']))
			# print('22222222222222222',k[0])
			third_id_list.append((i,t['id']))
			#有三级权限才添加
			if i == k[0]:
				t['children'] = x[(i,t['id'])]['children']
	# print(111, t['id'], x[t['id']])
	# x.pop(t['id'])

print(set(third_id_list))
for item in set(third_id_list):
	del x[item]

print('x',x)
for item in x:
	# print(item)
	for i in role_dict:
		if i == item[0]:
			print('111 item',item,x[item],x[item]['children'])
			children =  role_dict[i].get('children')
			rights = x[item]['children']
			if children:
				if rights not in children:
					print('111111111111')
					children.append(rights[0])
			else:
				role_dict[i]['children'] = rights


print(role_dict)